navigationGo.pngQuick Navigation
allprojects32.pngAll projects
hardware32.pngHardware
links32.pngLinks

favoriteStar32.pngTop projects
Alan numitron clock
Clapclap 2313/1386
SNES Pi Webserver
USB Volume/USB toys
Smokey amp
Laser cutter
WordClock
ardReveil v3
SNES Arcade cabinet
Game boy projects
cameleon
Home Presence Detector

github32.pngGitHub
AlanFromJapan

navigationMail.pngContact me

alanfjmail.png
3flags.pngWho's Alan?


Akizukidenshi
Elec-lab
Rand Nerd Tut
EEVblog
SpritesMods
AvrFreaks
Gameboy Dev
FLOZz' blog
Switch-science
Sparkfun
Suzusho
Datasheet Lib
Reddit Elec
Ermicro
Carnet du maker (fr)

raspi gpio fun

Last update: Thu Jun 5 22:25:41 2025
The idea is to add a few inputs/outputs on a Raspberry Pi puppy.

Presentation

Idea

  • I want a proper shutdown button for my webserver (Raspi 2) => I made a RaspiPower board for that.
  • I want to add some bling bling like blinking a led at each file served
  • Pilot so display to show message on a led board?
  • Points of interrest

  • Any pin is capable of GPIO. Not maybe 100% pure hardware (in terms of timing) but just any pin will be ok
  • RPi.GPIO lib can't do hardware PWM, all the PWM are software but at least you can have it on any pin
  • You can make the calls asynchronous by using the futures python package to run it on a threadpool
  • Implementation

    Bill of materials

    Schematics

    OS Settings

    Thanks to this person for sharing:
  • Need to run a Jessie raspbian so go for a sudo rpi-update and the usual sudo apt-get update ; sudo apt-get upgrade
  • If you do not run as root so the application user must be in the gpio group sudo adduser my-app-user gpio
  • And in case you still get a no access to /dev/mem, check the permissions and do sudo chown root.gpio /dev/gpiomem ; sudo chmod g+rw /dev/gpiomem
  • The above gpiomem change might be lost at reboot, so add it to your /etc/rc.local or in your startup script of your app
  • Source code

    PCB components
    Found the basic outline here so thanks for sharing mate!

    THE PCB
    On my github as usual.

    SHUTDOWN SCRIPT
    
    # External module imports                                                                                               
    import RPi.GPIO as GPIO
    import time, os
    
    # Pin Definitons:  
    buttonPin = 21
    
    
    def my_callback_shutdown(channel):
        print ("Shut down!")
        os.system("sudo shutdown -h now")
    
    
    # Pin Setup:           
    GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme
    GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.add_event_detect(buttonPin, GPIO.FALLING, callback=my_callback_shutdown, bouncetime=300)
    
    
    print("Waiting for shudown switch on GPIO%d" % (buttonPin))
    try:
        while 1:
            time.sleep(10)
    
    except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
        GPIO.cleanup() # cleanup all GPIO
    

    LED BLINK
    It's done in the project SNES Pi webserver check the file ledz.py.
    There's an interresting trick to use the concurrent.futures functions to have the blink running on another thread. Have a peek.

    Pictures


    Pinout from Element14

    //Circuit for my own version of a PowerBlock

    Links

    Helpful sources

  • Very nice tutorial on interrupt on Raspi with in RPi.GPIO
  • https://learn.sparkfun.com/tutorials/raspberry-gpio
  • Inspiration

    All content on this site is shared under the MIT licence (do what u want, don't sue me, hat tip appreciated)
    electrogeek.tokyo ~ Formerly known as Kalshagar.wikispaces.com and electrogeek.cc (AlanFromJapan [2009 - 2025])